package test.movies;

import katris.selenium.tests.util.BaseTest;
import org.testng.Assert;
import org.testng.annotations.Test;

public class SearchDescription_Absent extends BaseTest {


    // Logger variable
    private static final org.apache.log4j.Logger LOGGER = org.apache.log4j.Logger.getLogger(SearchDescription_Absent.class);

    // Film Name which is used for checking of Search process
    private String basicFilmName = "T-System";

    // Film Name
    private String filmName = "NotPresent";

    //@Test
    public void search_Description_Fail () {


        LOGGER.info("//========================================================");
        LOGGER.info("Starting test :  searching of film description ");
        LOGGER.info("//========================================================");

        LoginPage authorize = new LoginPage(app.getWebDriver(), app.getMovieUrl());

        // open Login Page
        authorize.openMoviesServer();

        // check if Login page is open
        boolean checkLoginPage = authorize.checkIfLoginPageIsOpen();
        Assert.assertTrue(checkLoginPage, "Login page is not open!!!!");

        // Login to application
        MainPage main = authorize.authorization("admin", "admin");
        Assert.assertNotNull(main,"Error while authorization: Can't find fields to authorize");

        // check if Main page is open
        boolean checkMainPage = main.checkIfMainPageIsOpen();
        Assert.assertTrue(checkMainPage,"User is not authorised !!!!");

        //search Description
        boolean checkSearch = main.doSearchDescription(filmName,basicFilmName);
        Assert.assertTrue(checkSearch,"Error during search of description !!!!");
        
        //check if description is found
        boolean checkResult = main.checkPresence(filmName);
        Assert.assertFalse(checkResult,"Description is not found!!!!");

        //do Log out
        LoginPage doLogOut = main.logOut();
        Assert.assertNotNull(doLogOut,"Button LogOut is not found!!!");

        // check if Login page is open
        boolean backLoginPage = doLogOut.checkIfLoginPageIsOpen();
        Assert.assertTrue(backLoginPage, "Back to Login page is not done!!!!");

    }
}
